import java.util.Arrays;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/29 9:57
 * @description:
 */
public class Solution1109 {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] diff = new int[n + 1];
        int[] res = new int[n];
        for (int i = 0; i < bookings.length; i++) {
            int first = bookings[i][0];
            int last = bookings[i][1];
            int seats = bookings[i][2];
            diff[first] += seats;
            if (last + 1 < diff.length) {
                diff[last + 1] -= seats;
            }
        }
        res[0] = diff[1];
        for (int i = 1; i < n; i++) {
            res[i] = res[i - 1] + diff[i + 1];
        }
        return res;
    }

    public static void main(String[] args) {
        Solution1109 solution = new Solution1109();
        System.out.println(Arrays.toString(solution.corpFlightBookings(new int[][]{{1, 2, 10}, {2, 3, 20}, {2, 5, 25}}, 5)));
        System.out.println(Arrays.toString(solution.corpFlightBookings(new int[][]{{1, 2, 10}, {2, 2, 15}}, 2)));
    }
}
